<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/8
 * Time: 13:46
 */
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use think\Db;


class FormatController extends AdminBaseController
{
    //商品列表页面
    public function index()
    {
       $data=Db::name('Format')->select();
        $this->assign("data", $data);
        return $this->fetch();
    }
    //新增
    public function add()
    {
        return $this->fetch();
    }
    /*
     * 新增品项
     * */
    public function addPost(){
        if ($this->request->isPost()){
            $res  = $this->request->param();
            $data['format']=$res['format_name'];
            $data['status']=$res['format'];
            $data['ctime']=time();
            $re=Db::name('Format')->insert($data);
            if($re){
                $this->success("添加成功！", url("Format/index"));
            }else{
                $this->error("添加失败，请重新添加！", url("Format/add"));
            }
        }
    } 
    /*
     * 2018/05/25 王磊  规格修改
     * */

    public function edit()
    {

        $id = $this->request->param("id");
        $data=DB::name('format')->where(['id'=>$id])->find();
        $this->assign("data", $data);
        return $this->fetch('format/edit');
    } 
    public function editpost(){
        if ($this->request->isPost()){
            $res  = $this->request->param();
            $where['id']=$res['brandid'];
            $data['format']=$res['format_name'];
            $data['status']=$res['format'];
            $data['ctime']=time();
            $re=Db::name('Format')->where($where)->update($data);
            if($re){
                $this->success("编辑成功！", url("Format/index"));
            }else{
                $this->error("编辑失败，请重新添加！", url("Format/add"));
            }
        }
    }
}